package com.wu.web.controller;

import com.wu.web.entity.TUser;
import com.wu.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wuyanshen
 * @date 2019-01-02 11:02 AM
 * @discription 描述
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/test")
    public String test() {
        return "user";
    }

    /**
     * 查询用户
     *
     * @param id
     * @param model
     * @return com.wu.web.entity.TUser
     * @date 2019/1/4 5:59 PM
     * @author wuyanshen
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public TUser getUser(@PathVariable String id, Model model) {
        TUser user = userService.findUser(id);
        return user;
    }

    /**
     *
     * 新增用户
     * http://localhost:8282/user/add/6/xiaoxiao/xiaoxiao/123123/18911111111
     *
     * @param id
     * @param username
     * @param password
     * @param account
     * @param phone
     * @param model
     * @return com.wu.web.entity.TUser
     * @date 2019/1/4 5:59 PM
     * @author wuyanshen
     */
    @RequestMapping(value = "/add/{id}/{username}/{account}/{password}/{phone}", method = RequestMethod.GET)
    @ResponseBody
    public TUser addUser(@PathVariable("id") String id, @PathVariable("username") String username, @PathVariable("password") String password, @PathVariable("account") String account, @PathVariable("phone") String phone, Model model) {
        TUser tUser = new TUser();
        tUser.setId(id);
        tUser.setUserName(username);
        tUser.setAccount(account);
        tUser.setPassword(password);
        tUser.setPhone(phone);
        userService.addUser(tUser);
        return tUser;
    }

}
